/**
 * created by lht 2008-9-18
 */

package com.hollycrm.ahunicom.sheet;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Array;

import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;

import com.hollycrm.ahunicom.sheet.IDAO;

public abstract class ExtendDAO extends HibernateDaoSupport implements IDAO {

private Object pojo;	

public ExtendDAO() {
	super();
}	

public void FormToDTOExchange(Object form,Object DTO) {
	try{			
		PropertyUtils.copyProperties(DTO,form);
		BeanInfo info=Introspector.getBeanInfo(DTO.getClass());
		PropertyDescriptor[] pds=info.getPropertyDescriptors();			
		for (int i = 0; i < pds.length; i++) {
			//System.out.println(pds[i].getDisplayName());				
			//System.out.println(pds[i].getReadMethod().invoke(iDTO,null));				
			if(pds[i].getPropertyType().equals(String.class)){					
				if((String)pds[i].getReadMethod().invoke(DTO,null)!=null){
					String str=StringManager.replaceAll((String)pds[i].getReadMethod().invoke(DTO,null),"'","''");
					pds[i].getWriteMethod().invoke(DTO,new Object[] {str.trim()});
				}					
			}else if(pds[i].getPropertyType().equals(Array.class)){
				Array ar=(Array)pds[i].getReadMethod().invoke(DTO,null);										
				if(ar!=null){
					for(int j=0 ;j<Array.getLength(ar);j++){	
						Array.set(ar,j,StringManager.replaceAll((String)Array.get(ar,j),"'","''").trim());
					}
					pds[i].getWriteMethod().invoke(DTO,new Object[] {ar});
				}
			}					
		}			

	}catch (Exception e){

		e.printStackTrace();
	}
}

//public void DAOToPOJOExchange(Object dto){		
//	try {
//		PropertyUtils.copyProperties(pojo,dto);
//		
//	} catch (Exception e) {				
//		
//	}
//}
//public Object DAOToPOJOExchange(Object dto,Object po){
//	try {
//		PropertyUtils.copyProperties(po,dto);
//	} catch (Exception e) {				
//		
//	}
//	return pojo;
//}	

public Object getPojo() {
	return pojo;
}

public void setPojo(Object object) {
	pojo = object;
}


public Object delete(Object ob, String str) {
	return null;
}


public Object doElse(Object ob, String str) {
	return null;
}

public Object elseQuery(Object ob, String str) {
	return null;
}

public Object find(Object ob, String str) {
	return null;
}

public Object iterate(Object ob, String str) {
	return null;
}

public Object load(Object ob, String str) {
	return null;
}

public Object query(Object ob, String str) {
	return null;
}

public Object save(Object ob, String str) {
	return null;
}

public Object saveorUpdate(Object ob, String str) {
	return null;
}

public Object update(Object ob, String str) {
	return null;
}

public Object delete(Object ob) {
	return null;
}

public Object doElse(Object ob) {
	return null;
}

public Object elseQuery(Object ob) {
	return null;
}

public Object find(Object ob) {
	return null;
}

public Object iterate(Object ob) {
	return null;
}

public Object load(Object ob) {
	return null;
}

public Object query(Object ob) {
	return null;
}

public Object save(Object ob) {
	return null;
}

public Object saveorUpdate(Object ob) {
	return null;
}

public Object update(Object ob) {
	return null;
}

}